var FreureaAssistant = Class.create(AbstractModule, {

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'US'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));


	this.controller.setupWidget("bunField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	this.controller.setupWidget("ureaField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	this.controller.setupWidget("sercreatField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: creatinine});
	this.controller.setupWidget("urcreatField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	
},


unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("bunUnit").update("<span class=\"si\">mg/dL</span>");
$("ureaUnit").update("<span class=\"si\">mg/dL</span>");
$("sercreatUnit").update("<span class=\"si\">mg/dL</span>");
$("urcreatUnit").update("<span class=\"si\">mg/dL</span>");
}

if (unitchoice){
$("bunUnit").update("<span class=\"si\">mmol/L</span>");
$("ureaUnit").update("<span class=\"si\">mmol/L</span>");
$("sercreatUnit").update("<span class=\"si\">&mu;mol/L</span>");
$("urcreatUnit").update("<span class=\"si\">&mu;mol/L</span>");;
}
},


	calculate: function() {
	var result = freureacalc(this.togglemodel.togglestate,$("bunField").mojo.getValue(), $("ureaField").mojo.getValue(), $("sercreatField").mojo.getValue(), $("urcreatField").mojo.getValue());
	creatinine=result.creatinine;
	
	if (isNaN(result.freurea)){
	return errormsg;
	}
	else {
	return "The FEUrea is " + result.freurea +"%";
	}
	}
});




